#!/usr/bin/env bash

help(){
    cat<<__EOF__
    usage:  m dns [ flush | help ]

    Examples:
      m dns flush       # flushes local DNS
__EOF__
}


flushdns(){
    VERSION=$(sw_vers -productVersion)
    echo "Flushing dns..."
    if echo $VERSION | grep -E '^10\.10(\.[0-3])?$' >/dev/null 2>&1; then
        sudo discoveryutil mdnsflushcache
    elif echo $VERSION | grep -E '^10\.6(\.[0-8])?$' >/dev/null 2>&1; then
        sudo dscacheutil -flushcache
    else
        sudo killall -HUP mDNSResponder
    fi
}


case $1 in
    help)
        help
        ;;
    flush)
        flushdns
        ;;
    *)
        help
        ;;
esac

# vim: ts=4 sw=4 softtabstop=4 expandtab
